function getCountries(userCountry, userProvince, userCity) {
	var country = document.getElementById("country");
	$.ajax({
		url : "/skyline/site/getCountries.html",
		type : "POST",
		dataType : "json",
		contentType : "application/x-www-form-urlencoded; charset=utf-8",
		success : function(msg) {
			for ( var i = 0; i < msg.length; i++) {
				var varItem = new Option(msg[i].name, msg[i].name + "-"
						+ msg[i].id);
				if (msg[i].name == userCountry) {
					varItem.selected = true;
				}
				country.options.add(varItem);
			}
			getProvinces(userProvince, userCity);
		}
	});
}
function getProvinces(userProvince, userCity) {
	var province = document.getElementById("province");
	var country = document.getElementById("country").value;
	var countryId = country.split("-")[1];
	$.ajax({
		url : "/skyline/site/getSubSites.html",
		type : "POST",
		data : "siteId=" + countryId,
		dataType : "json",
		contentType : "application/x-www-form-urlencoded; charset=utf-8",
		success : function(msg) {
			province.options.length = 0;
			for ( var i = 0; i < msg.length; i++) {
				var varItem = new Option(msg[i].name, msg[i].name + "-"
						+ msg[i].id);
				if (msg[i].name == userProvince) {
					varItem.selected = true;
				}
				province.options.add(varItem);
			}
			getCities(userCity)
		}
	});
}
function getCities(userCity) {
	var city = document.getElementById("city");
	var province = document.getElementById("province").value;
	var provinceId = province.split("-")[1];
	$.ajax({
		url : "/skyline/site/getSubSites.html",
		type : "POST",
		data : "siteId=" + provinceId,
		dataType : "json",
		contentType : "application/x-www-form-urlencoded; charset=utf-8",
		success : function(msg) {
			city.options.length = 0;
			for ( var i = 0; i < msg.length; i++) {
				var varItem = new Option(msg[i].name, msg[i].name + "-"
						+ msg[i].id);
				if (msg[i].name == userCity) {
					varItem.selected = true;
				}
				city.options.add(varItem);
			}
		}
	});
}
function CheckItem(FieldID, FieldName, MaxLength) {
	// alert(" ");
	var Field = document.getElementById(FieldID);
	var Msg = document.getElementById("Msg_" + FieldID);

	if (Field.value.length > MaxLength) {

		Msg.style.display = "block";
		document.getElementById("Img_" + FieldID).src = "img/commons/success_min.gif";
		document.getElementById("Font_" + FieldID).color = "red";
		document.getElementById("Font_" + FieldID).innerHTML = FieldName
				+ "超过最大长度" + MaxLength + ",请重新输入!";
		Field.className = "InputError";
		return false;
	} else {
		Msg.style.display = "block";
		document.getElementById("Img_" + FieldID).src = "img/commons/success_min.gif";
		document.getElementById("Font_" + FieldID).color = "black";
		document.getElementById("Font_" + FieldID).innerHTML = FieldName
				+ "输入正确";
		Field.className = "InputOK";
		return true;
	}
}

function CheckAll() {
	if (CheckItem('nickname', '昵称', 20) & CheckItem('realname', '真实姓名', 20)
			& CheckItem('address', '现居地', 60) & CheckItem('hometown', '家乡', 60)) {

		document.all.UserInfoForm.submit();
		// return true;
	} else {
		alert("个人信息输入有误，请重新填写！");
		return false;
	}
}

function UpdatePassword() {
	var Font = document.getElementById("passwordConfirm_font");
	alert($('#oldPassword').value);
	$.ajax({
		type : "POST",
		url : '/skyline/user/modifypassword.html',
		data : "oldPassword=" + $('#oldPassword').val()+ "&password=" + $('#password').val()
				+ "&passwordConfirm=" + $('#passwordConfirm').val(),
		dataType : "json",
		contentType : "application/x-www-form-urlencoded; charset=utf-8",
		success : function(msg) {
			// alert(msg);
			if (msg == "true") {

				Font.innerHTML = "";
				return true;
			} else {
				Font.innerHTML = "密码错误";
				return false;
			}
		}
	});
}
function CheckOldPassword(FieldID, value) {
	var Field = document.getElementById("oldpassword");
	var Msg = document.getElementById("oldpassword_div");
	var Img = document.getElementById("oldpassword_img");
	var Font = document.getElementById("oldpassword_font");
	$.ajax({
		type : "POST",
		url : '/skyline/user/checkoldpassword/' + value + '.html',
		data : null,
		success : function(msg) {
			// alert(msg);
			if (msg == "true") {
				Msg.style.display = "block";
				Img.src = success_gif;
				Font.innerHTML = "";
				return true;
			} else {
				Msg.style.display = "block";
				Img.src = fail_gif;
				Font.color = fail_font_color;
				Font.innerHTML = "密码错误";
				return false;
			}
		}
	});
}
